import Mock from 'mockjs';

// 图谱列表
Mock.mock(/\/api\/v1\/graph-builder\/list/, 'get', (options: { url: string }) => {
  const params = new URLSearchParams(options.url.split('?')[1]);
  const page = parseInt(params.get('page') || '1');
  const pageSize = parseInt(params.get('pageSize') || '20');

  return {
    code: 200,
    data: {
      total: 100,
      list: Mock.mock({
        [`list|${pageSize}`]: [{
          'id|+1': 1,
          'name': '@ctitle(5, 10)',
          'type|1': ['结构化', '非结构化'],
          'createTime': '@datetime',
          'nodeCount|1000-10000': 1000,
          'edgeCount|1000-10000': 1000,
          'status|1': ['building', 'completed', 'failed']
        }]
      }).list
    },
    message: 'success'
  };
});

// 创建结构化图谱
Mock.mock('/api/v1/graph-builder/structured', 'post', () => {
  return {
    code: 200,
    data: {
      id: Mock.Random.guid(),
      name: Mock.Random.ctitle(5, 10),
      type: '结构化',
      createTime: Mock.Random.datetime(),
      nodeCount: 0,
      edgeCount: 0,
      status: 'building'
    },
    message: '创建成功'
  };
});

// 创建非结构化图谱
Mock.mock('/api/v1/graph-builder/unstructured', 'post', () => {
  return {
    code: 200,
    data: {
      id: Mock.Random.guid(),
      name: Mock.Random.ctitle(5, 10),
      type: '非结构化',
      createTime: Mock.Random.datetime(),
      nodeCount: 0,
      edgeCount: 0,
      status: 'building'
    },
    message: '创建成功'
  };
});

// 图谱详情
Mock.mock(/\/api\/v1\/graph-builder\/[\w-]+$/, 'get', () => {
  return {
    code: 200,
    data: {
      id: Mock.Random.guid(),
      name: Mock.Random.ctitle(5, 10),
      type: '结构化',
      description: Mock.Random.cparagraph(1, 3),
      createTime: Mock.Random.datetime(),
      status: 'completed',
      statistics: {
        nodeCount: Mock.Random.integer(1000, 10000),
        edgeCount: Mock.Random.integer(1000, 10000),
        nodeTypes: Mock.mock({
          'list|3-6': [{
            'type': '@ctitle(2,4)',
            'count|100-1000': 100
          }]
        }).list,
        edgeTypes: Mock.mock({
          'list|3-6': [{
            'type': '@ctitle(2,4)',
            'count|100-1000': 100
          }]
        }).list
      },
      graphData: {
        nodes: [],
        edges: []
      }
    },
    message: 'success'
  };
});

// 删除图谱
Mock.mock(/\/api\/v1\/graph-builder\/[\w-]+$/, 'delete', () => {
  return {
    code: 200,
    message: '删除成功'
  };
});